// Learn cc.Class:
//  - https://docs.cocos.com/creator/manual/en/scripting/class.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

cc.Class({
    extends: cc.Component,

    properties: {

    },

    onLoad () {
      console.log("welcome --onLoad")
      this.changeScale()
    },

    start () {
        console.log("welcome --start")
    },
    changeScale(){
      var fadeTiem = 3000; //总时间
      var nowTime = Date.now(); //开始淡出的时间
      var timePercent = 0; //百分比
      var self = this
      var changeFade = function() {
             //每过一段时间就减少一点透明度
            var duringTime = Date.now() - nowTime; //已经过去的时间
            timePercent = duringTime / fadeTiem; //已经过去的时间所占的百分比
            if(timePercent > 0.6){
                timePercent = 0.6;
            }
            self.node.scale = 0.4 + timePercent; //设置为他剩余的透明度
            if(timePercent == 0.6){
              cc.director.loadScene("farm");
              return;
          }else{
              setTimeout(changeFade,30);
          }
      }
      setTimeout(changeFade,30);
    },

    update (dt) {

    },
});
